﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace YmtAuth.LogService
{
    public class AuthSafeVerifyLog : LogEntityBase
    {

        public string RequestId { get; set; }
        
        public virtual string _id { 
            
            get 
            {
                if (string.IsNullOrEmpty(RequestId))
                    return Guid.NewGuid().ToString("N");
                else
                    return RequestId;
            }
        }
        public string sLoginId { get; set; }
        public int iAction { get; set; }
        public string sLoginIp { get; set; }
        public string sSummary { get; set; }
        public virtual DateTime dAddTime { get { return DateTime.Now; } }
        /// <summary>
        /// 登录客户端类型：www.ymatou.com ，app，dms，xxx.admin,ali,weibo
        /// </summary>    
        public string sClientType { get; set; }
        public double RunTime { get; set; }
        /// <summary>
        /// ChannelSource
        /// </summary>      
        public string CSource { get; set; }
        /// <summary>
        /// Terminal Source
        /// </summary>       
        public string TSource { get; set; }
        public string Desc { get; set; }
        public string AuthType { get; set; }
        public int ResponseCode { get; set; }
        public string DeviceId { get; set; }
        public string ClientId { get; set; }

        public string ServerIp
        {
            get
            {
                if (string.IsNullOrEmpty(ip))
                    ip = LocalIp();
                return ip;
            }
        }
        public override string LogType
        {
            get
            {
                return "AuthSafeVerifyLog";
            }
        }

        private static string ip;
        public string LocalIp()
        {
            var ips = Dns.GetHostEntry(Dns.GetHostName())
                 .AddressList.FirstOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork);
            return ips == null ? null : ips.ToString();
        }
    }
}
